/********************************** (C) COPYRIGHT *******************************
 * File Name          : main.c
 * Author             : WCH
 * Version            : V1.0.0
 * Date               : 2022/08/08
 * Description        : Main program body.
 *********************************************************************************
 * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
 * Attention: This software (modified or not) and binary are used for 
 * microcontroller manufactured by Nanjing Qinheng Microelectronics.
 *******************************************************************************/
/*
 *@Note
 *GPIO routine:
 *PD0 push-pull output.
 *
*/
/*
*  PC6     MAIN1
*  PC7     MAIN2
*  PC0     MBIN1
*  PD3     MBIN2
*  PC5     MCIN1
*  PC2     MCIN2
*  PD2     MDIN1
*  PC1     MDIN2
*
*  PD4     MEN
*
*  PC3     MFAULT1
*  PC4     MFAULT2
*/
#include "debug.h"
#include "At.h"
#include "SysInit.h"
#include "Motors.h"
//#include "CH32V_PWM.h"

#define PWM_DUTY_MAX 100

/* Global define */

/* Global Variable */

/*
 * @fn      main
 *
 * @brief   Main program.
 *
 * @return  none
 */
int main(void)
{
    u8 i = 0;

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    SystemCoreClockUpdate();
    Delay_Init();

#if (SDI_PRINT == SDI_PR_OPEN)
    SDI_Printf_Enable();
#else
    USART_Printf_Init(115200);
#endif

    printf("SystemClk:%d\r\n", SystemCoreClock);
    printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
    printf("GPIO Toggle TEST\r\n");
    
    //GPIO_WriteBit(GPIOD, GPIO_Pin_4, 1);

    InitMotors();




//    GPIO_WriteBit(GPIOC, GPIO_Pin_1, 0);


 //   InitMotors();
    AtCfg();
    AtProc();

    while(1)
    {
        Delay_Ms(1000);
        //GPIO_WriteBit(GPIOD, GPIO_Pin_4, (i == 0) ? (i = Bit_SET) : (i = Bit_RESET));
    }
}
